/*
 * gengraph.c
 *
 *  Created on: 10/08/2013
 *      Author: marcio
 */

#include <Graph.h>
#include <stdio.h>
#include <string.h>

int** edges;
long n;
int count;

int gengraph(int i, int j){
	if(j >= n){
		print();
		gengraph(i+1, i+1, n);
	}

	if(i <= j){
		if( i != j){
			edges[i][j] = 1;
			gengraph(i, j+1, n);
		}
		edges[i][j] = 0;
		gengraph(i, j+1, n);
	}
}

int print(){
	char newfile[500];
	strcpy("grafo", newfile);
	strcat(newfile, ltoa(n));
	strcat(newfile, "_");
	strcat(newfile, ltoa(count));
	count++;
	FILE* nf = open(newfile);
	long m = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(edges[i][j] == 1) m++;
		}
	}
	fprintf(nf,"p %lu %lu \n", n,m);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(edges[i][j] == 1)fprintf(nf,"e %lu %lu \n", i,j);
		}
	}
	fclose(nf);
}


int main(int argc, char *argv[]){
	if(argc < 1){
		printf("ERRO: número de argumentos inválido \n");
		printf("WARNING: Adicione o número de arestas ao grafo \n");
	}else{
		count = 0;
		n = atol(argv[1]);
		gengraph(0,0);
	}
	return 0;
}


